<?php
// Version stuff...

$small_version = $etomite->config['small_version'];
$patch_level = $etomite->config['patch_level'];
$release = $etomite->config['release'];

if(@$handle = fopen("http://www.etofork.com/status/status.php", "r"))
{
  $newversion = fgets($handle, 4096);
  fclose($handle);
  $newrelease = trim(strip_tags($newversion));
  if($small_version.$patch_level == $newrelease)
  {
    $newversiontext = $etomite->_lang['sys_info_version_ok'];
  }
  if($small_version.$patch_level < $newrelease)
  {
    $newversiontext = $etomite->_lang['sys_info_version_update']."<b>".$newrelease."</b>";
  }
  if($small_version.$patch_level > $newrelease)
  {
    $newversiontext = $etomite->_lang['sys_info_version_ok'];
  }
}
else
{
  $newversiontext = $etomite->_lang['sys_info_version_no_connect'];
}
?>

<section class="content-header">
    <h1>
        <?php echo $etomite->_lang['system_information']; ?>
        <small>Welcome</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="./"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="active"><i class="fa fa-gear"></i> <?php echo $etomite->_lang['system_information']; ?></li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <div class="nav-tabs-custom">
        <!-- Tabs within a box -->
        <ul class="nav nav-tabs">
            <li class="active"><a href="#recentDocs" data-toggle="tab"><?php echo $etomite->_lang["activity_title"]; ?></a></li>
            <li><a href="#serverInfo" data-toggle="tab"><?php echo $etomite->_lang['server_info']; ?></a></li>
            <li><a href="#dbtables" data-toggle="tab"><?php echo $etomite->_lang['database_tables']; ?></a></li>
            <li><a href="#userpanel" data-toggle="tab"><?php echo $etomite->_lang["onlineusers_title"]; ?></a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id="recentDocs" style="position: relative;">
            	<p><?php echo $etomite->_lang["sys_info_activity_message"]; ?></p>
                <table border="0" cellpadding="0" cellspacing="0" width="100%" id="rdocs-tbl">
                      <thead>
                      <tr>
                        <th><?php echo $etomite->_lang['id']; ?></th>
                        <th><?php echo $etomite->_lang['document_title']; ?></th>
                        <th><?php echo $etomite->_lang["sys_info_userid"]; ?></th>
                        <th><?php echo $etomite->_lang['datechanged']; ?></th>
                      </tr>
                      </thead>
                      <tbody>
                <?php
                $sql = "SELECT id, pagetitle, editedby, editedon, type FROM ".$etomite->db."site_content WHERE ".$etomite->db."site_content.deleted=0 ORDER BY editedon DESC LIMIT 20";
                $rs = $etomite->dbQuery($sql);
                $limit = $etomite->recordCount($rs);
                if($limit < 1)
                {
                  echo $etomite->_lang['sys_info_nothing_found']."<p />";
                }
                else
                {
                  for ($i = 0; $i < $limit; $i++)
                  {
                    $content = $etomite->fetchRow($rs);
                    $sql = "select username from ".$etomite->db."manager_users WHERE id=".$content['editedby'];
                    $rs2 = $etomite->dbQuery($sql);
                    $limit2 = $etomite->recordCount($rs2);
                
                    $user = $etomite->fetchRow($rs2);
                    ?>
                    <tr>
                        <td><?php echo $content['id'];?></td>
                        <td><a href='javascript:;' onclick="Etomite.editDocument('<?php echo $content['id'];?>', '', <?php (($content['type']=='reference') ? "'true'":"''")?>);"><?php echo $content['pagetitle'];?></a></td>
                        <td><?php echo $user['username'];?></td>
                        <td><?php echo strftime($etomite->config['date_format']." @ ".$etomite->config['time_format'], $content['editedon']+$etomite->config['server_offset_time']);?></td>
                    </tr>
                    <?php
                  }
                }
                ?>
                
                      </tbody>
                </table>
                <script type="text/javascript">
                    tTable = $('#rdocs-tbl').dataTable({
                            "bJQueryUI": true,
                            "sPaginationType": "full_numbers"
                        });
                </script>
            </div>
            <div class="tab-pane" id="serverInfo" style="position: relative;">
            	<p><?php echo $etomite->_lang['sys_info_eto_install_info']; ?></p>
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                  <tr>
                  <td width="150"><?php echo $etomite->_lang['sys_info_eto_version'];?></td>
                  <td width="20">&nbsp;</td>
                  <td><b><?php echo $small_version.$patch_level ?>&nbsp;</b><?php echo $newversiontext; ?></td>
                  </tr>
                  <tr>
                  <td width="150"><?php echo $etomite->_lang['sys_info_eto_codename'];?></td>
                  <td width="20">&nbsp;</td>
                  <td><b><?php echo $etomite->config['code_name'] ?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_acc_perms'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo $use_udperms==1 ? $etomite->_lang['sys_info_perms_enabled'] : $etomite->_lang['sys_info_perms_disabled']; ?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_time'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo strftime($etomite->config['time_format'], time()); ?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_local_time'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo strftime($etomite->config['time_format'], time()+$etomite->config['server_offset_time']); ?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_offset'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo $etomite->config['server_offset_time']/(60*60) ?></b> <?php echo $etomite->_lang['sys_info_offset_text'];?></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_db_name'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo $etomite->dbConfig['dbase'] ?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_db_server'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo $etomite->dbConfig['host'] ?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_db_prefix'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo $etomite->dbConfig['table_prefix'] ?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_base_page_abs'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo MANAGER_PATH;?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_base_page_rel'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo str_replace(absolute_base_path, "", MANAGER_PATH);?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td>Relative Base Path</td>
                  <td>&nbsp;</td>
                  <td><b><?php echo relative_base_path;?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td><?php echo $etomite->_lang['sys_info_base_page_www'];?></td>
                  <td>&nbsp;</td>
                  <td><b><?php echo MANAGER_URL;?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td>Session Name:</td>
                  <td>&nbsp;</td>
                  <td><b><?php echo session_name();?>&nbsp;</b></td>
                  </tr>
                  <tr>
                  <td>Session ID:</td>
                  <td>&nbsp;</td>
                  <td><b><?php echo session_id();?>&nbsp;</b></td>
                  </tr>
                </table>
            </div>
            <div class="tab-pane" id="dbtables" style="position: relative;">
            	<p><?php echo $etomite->_lang['sys_info_table_instructions'];?></p>
                <table border="0" cellpadding="0" cellspacing="0" width="100%" class="table-striped">
                <thead>
                <tr>
                  <th width="160"><?php echo $etomite->_lang['sys_info_table_name'];?></th>
                  <th width="40" align="right"><?php echo $etomite->_lang['sys_info_records'];?></th>
                  <th width="120" align="right"><?php echo $etomite->_lang['sys_info_data_size'];?></th>
                  <th width="120" align="right"><?php echo $etomite->_lang['sys_info_overhead']?></th>
                  <th width="120" align="right"><?php echo $etomite->_lang['sys_info_effective_size'];?></th>
                  <th width="120" align="right"><?php echo $etomite->_lang['sys_info_index_size'];?></th>
                  <th width="120" align="right"><?php echo $etomite->_lang['sys_info_total_size'];?></th>
                </tr>
                </thead>
                <tbody>
                <?php
                $sql = "SHOW TABLE STATUS FROM ".$etomite->dbConfig['dbase'].";";
                $rs = $etomite->dbQuery($sql);
                $limit = $etomite->recordCount($rs);
                for ($i = 0; $i < $limit; $i++)
                {
                  $log_status = $etomite->fetchRow($rs);
                ?>
                
                      <tr class="" title="<?php echo $log_status['Comment']; ?>" style="cursor:default">
                      <td class="success"><?php echo $log_status['Name']; ?></td>
                      <td align="right"><?php echo $log_status['Rows']; ?></td>
                      <td align="right"><?php echo nicesize($log_status['Data_length']+$log_status['Data_free']); ?></td>
                      <td align="right"><?php echo $log_status['Data_free']>0 ? nicesize($log_status['Data_free']) : "-" ; ?></td>
                      <td align="right"><?php echo nicesize($log_status['Data_length']-$log_status['Data_free']); ?></td>
                      <td align="right"><?php echo nicesize($log_status['Index_length']); ?></td>
                      <td align="right"><?php echo nicesize($log_status['Index_length']+$log_status['Data_length']+$log_status['Data_free']); ?></td>
                      </tr>
                
                <?php
                $total = $total+$log_status['Index_length']+$log_status['Data_length'];
                $totaloverhead = $totaloverhead+$log_status['Data_free'];
                }
                ?>
                
                  <tr>
                  <td valign="top"><b><?php echo $etomite->_lang['sys_info_totals']; ?>:</b></td>
                  <td colspan="2">&nbsp;</td>
                  <td align="right" valign="top"><?php echo $totaloverhead>0 ? "<b style='color:#990033'>".nicesize($totaloverhead)."</b><br>(".number_format($totaloverhead)." B)" : "-"; ?></td>
                  <td colspan="2">&nbsp;</td>
                  <td align="right" valign="top"><?php echo "<b>".nicesize($total)."</b><br>(".number_format($total)." B)"; ?></td>
                  </tr>
                  </tbody>
                </table>
                <?php
                if($totaloverhead>0)
                {
                  echo "<p>".$etomite->_lang['sys_info_table_clear']."</p>";
                }
                ?>
            </div>
            <div class="tab-pane" id="userpanel" style="position: relative;">
            	<p><?php echo $etomite->_lang["onlineusers_message"]; ?><br />
                <b><?php echo $etomite->_lang['current_time:'].strftime($etomite->config['time_format'], time()+$etomite->config['server_offset_time']); ?></b></p>
                <table border="0" cellspacing="0" cellpadding="0" width="100%" class="table-striped">
                  <thead>
                    <tr>
                    <td><?php echo $etomite->_lang["onlineusers_user"];?></td>
                    <td><?php echo $etomite->_lang["onlineusers_userid"];?></td>
                    <td><?php echo $etomite->_lang["onlineusers_ipaddress"];?></td>
                    <td><?php echo $etomite->_lang["onlineusers_lasthit"];?></td>
                    <td><?php echo $etomite->_lang["onlineusers_action"];?></td>
                    <td><?php echo $etomite->_lang["onlineusers_action_id"];?></td>
                    </tr>
                  </thead>
                  <tbody>
                  
                  <?php
                    $timetocheck = (time()-(60*20));
                    
                    include_once("includes/actionlist.inc.php");
                    
                    $sql = "SELECT * FROM ".$etomite->db."active_users WHERE ".$etomite->db."active_users.lasthit>$timetocheck ORDER BY username ASC";
                    $rs = $etomite->dbQuery($sql);
                    $limit = $etomite->recordCount($rs);
                    if($limit < 1)
                    {
                      echo $etomite->_lang['sys_info_no_active_users'];
                    }
                    else
                    {
                      for ($i = 0; $i < $limit; $i++)
                      {
                        $activeusers = $etomite->fetchRow($rs);
                        $currentaction = getAction($activeusers['action'], $activeusers['id']);
                        echo "<tr><td><b>".$activeusers['username']."</b></td><td>".$activeusers['internalKey']."</td><td>".$activeusers['ip']."</td><td>".strftime($etomite->config['time_format'], $activeusers['lasthit']+$etomite->config['server_offset_time'])."</td><td>$currentaction</td><td align='right'>".$activeusers['action']."</td></tr>";
                      }
                    }
                    ?>
                    
                  </tbody>
                </table>
            </div>
        </div>
    </div>
</section>